﻿using System;
using System.Linq;
using System.Linq.Expressions;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace nMongo
{
    public partial class MongoEngine
    {
        /// <summary>
        /// Checks if an object exists in the collection, giving a specified condition.
        /// </summary>
        /// <param name="predicate">Expression to evaluate and determines the condition satisfaction.</param>
        public bool Exists<T>(Expression<Func<T, bool>> predicate)
            where T : class
        {
            return this.Database.GetCollectionFromType<T>().AsQueryable().Any(predicate);
        }
    }
}
